package pers.yurwisher.rubick.manager.service.impl;

import cn.hutool.core.lang.Assert;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pers.yurwisher.rubick.common.base.impl.BaseServiceImpl;
import pers.yurwisher.rubick.common.wrapper.PageR;
import pers.yurwisher.rubick.manager.entity.InterfaceDefinition;
import pers.yurwisher.rubick.manager.mapper.InterfaceDefinitionMapper;
import pers.yurwisher.rubick.manager.service.IInterfaceDefinitionService;
import pers.yurwisher.rubick.manager.pojo.fo.InterfaceDefinitionFo;
import pers.yurwisher.rubick.manager.pojo.qo.InterfaceDefinitionQo;
import pers.yurwisher.rubick.manager.pojo.to.InterfaceDefinitionTo;
import pers.yurwisher.rubick.manager.pojo.vo.InterfaceDefinitionVo;

/**
 * @author yq
 * @date 2021-04-14 12:23:15
 * @description 系统取号关系
 * @since V1.0.0
 */
@Service
public class InterfaceDefinitionServiceImpl extends BaseServiceImpl<InterfaceDefinitionMapper,InterfaceDefinition> implements IInterfaceDefinitionService{

    /**
     * 新增
     * @param fo 参数
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(InterfaceDefinitionFo fo){
        InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
        BeanUtils.copyProperties(fo,interfaceDefinition);
        baseMapper.insert(interfaceDefinition);
    }

    /**
     * 更新
     * @param id 主键
     * @param fo 参数
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(Long id,InterfaceDefinitionFo fo){
        InterfaceDefinition interfaceDefinition = baseMapper.selectById(id);
        Assert.notNull(interfaceDefinition);
        BeanUtils.copyProperties(fo,interfaceDefinition);
        baseMapper.updateById(interfaceDefinition);
    }

    /**
     * 列表
     * @param qo 查询参数
     * @return 分页对象
     */
    @Override
    @SuppressWarnings("unchecked")
    public PageR<InterfaceDefinitionTo> list(InterfaceDefinitionQo qo){
        return super.toPageR(baseMapper.list(super.toPage(qo),qo));
    }


    /**
    * 详情
    * @param id 主键
    * @return InterfaceDefinitionVo
    */
    @Override
    public InterfaceDefinitionVo get(Long id){
        return baseMapper.get(id);
    }

     /**
     * 删除
     * @param id 主键
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(Long id){
        baseMapper.deleteById(id);
    }
}
